package com.barcamp.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.barcamp.entity.RegisterData;
import com.exception.PersistenceException;

public class RegisterDao extends SqlMapClientDaoSupport{
	private Logger logger = Logger.getLogger(RegisterDao.class);
	private List<RegisterData> resultList;
	//private List<EventType> eventList;
	
	public void registerAttendance(RegisterData registerData)throws PersistenceException{
		try{
			getSqlMapClientTemplate().insert("RegisterData.insertAttendance", registerData);
			logger.info( registerData.getName() + " is successfully inserted.");
		}catch(DataAccessException ex){
			 logger.error(registerData.getName() + " is failed to insert.", ex);
	         throw new PersistenceException("Failed to insert user.", ex);
	    }
	}
	public List<RegisterData> findRegisterData()throws PersistenceException{
		 try {
			 resultList =(List<RegisterData>)getSqlMapClientTemplate().queryForList("RegisterData.findAllRegister");
            // logger.info("All of books is successfully found.");
	      } catch (DataAccessException ex) {
	          //logger.error("All of books is failed to find.");
	          throw ex;
	      }
		 return resultList;
	}
	
	public void updateRegister(RegisterData registerData)throws PersistenceException{
		try{
			getSqlMapClientTemplate().update("RegisterData.updateAttendance", registerData);
			logger.info( registerData.getName() + " is successfully updated.");
		}catch(DataAccessException ex){
			 logger.error(registerData.getName() + " is failed to update.", ex);
	         throw new PersistenceException("Failed to update attendance.", ex);
	    }
	}
	
	public  List<RegisterData>  findByPresentStatus(int value)throws PersistenceException{
		 try {
			 resultList =(List<RegisterData>)getSqlMapClientTemplate().queryForList("RegisterData.findByPresentStatus",value);
			 // logger.info("All of books is successfully found.");
	      } catch (DataAccessException ex) {
	          //logger.error("All of books is failed to find.");
	          throw ex;
	      }
		 return resultList;
	}

	public  List<RegisterData>  findByAbsenceStatus(int id)throws PersistenceException{

		 try {
			 resultList =(List<RegisterData>)getSqlMapClientTemplate().queryForList("RegisterData.findByAbsenceStatus",id);
           // logger.info("All of books is successfully found.");
	      } catch (DataAccessException ex) {
	          //logger.error("All of books is failed to find.");
	          throw ex;
	      }
		 return resultList;
	}

}
